package com.define.ssh.dao.impl;

import java.math.BigInteger;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.criterion.CriteriaQuery;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.engine.TypedValue;
import org.springframework.stereotype.Repository;

import com.define.ssh.dao.ClientVersionDataDao;
import com.define.ssh.model.ClientVersionData;

@Repository("clientVersionDataDaoImpl")
public class ClientVersionDataDaoImpl extends
		BaseDaoImpl<ClientVersionData, Long> implements ClientVersionDataDao {

	@Override
	public List<String> findVersionGroupByType(int type) {
		Criteria criteria = super.getSession().createCriteria(
				ClientVersionData.class);
		criteria.add(Restrictions.eq("type", type));
		criteria.setProjection(Projections.groupProperty("version"));
		return criteria.list();
	}

	@Override
	public int countByVersion(String version) {
		Query sqlQuery = getSession().createSQLQuery("select  count(*)  from t_client_version_data where version='"+version+"'");
		List list = sqlQuery.list();
		return ((BigInteger)list.get(0)).intValue();
	}

}